<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2021/7/18
 * Time: 18:57
 */
namespace app\admin\logic;

use think\facade\View;

class Goods
{
    public static function getGoodListWhere()
    {
        $where=[];
        $hot=request()->param('is_hot');
        if($hot!=''){
            $where[]=['is_hot','=',$hot];
        }
        $show=request()->param('is_show');
        if($show!=''){
            $where[]=['is_show','=',$show];
        }
        $down=request()->param('is_down');
        if($down!=''){
            $where[]=['is_down','=',$down];
        }
        $cid=request()->param('cid');
        if($cid!=''){
            $where[]=['cid','=',$cid];
        }
        $name=request()->param('keywords');
        if($name!=''){
            $where[]=['ecm_goods.name','like',"%{$name}%"];
        }
        if (request()->param('min')!='' && request()->param('max')!=''){
            $where[]=['price_shop','>=',request()->param('min')];
            $where[]=['price_shop','<=',request()->param('max')];
        }elseif(request()->param('min')!=''){
            $where[]=['price_shop','>=',request()->param('min')];
        }elseif (request()->param('max')!=''){
            $where[]=['price_shop','<=',request()->param('max')];
        }
        if(request()->param('startTime')!='' && request()->param('endTime')!=''){
            $where[]=['ecm_goods.addtime','> time',request()->param('startTime')];
            $where[]=['ecm_goods.addtime','< time',request()->param('endTime')];
        }
        View::assign('keywords','');
        $order=request()->param('order');
        if($order=='g.id asc'){
            View::assign('order','g.addtime desc');
            View::assign('jian','↑');
        }elseif ($order=='g.addtime desc'){
            View::assign('order','g.addtime asc');
            View::assign('jian','↓');
        }elseif ($order=='g.addtime asc'){
            View::assign('order','g.id asc');
            View::assign('jian','');
        }
        return [$where,$order];
    }

    public static function getOrderListWhere()
    {
        $where=[];
        if(request()->post('startTime')!='' && request()->post('endTime')!=''){
            $where[]=['addtime','> time',request()->post('startTime')];
            $where[]=['addtime','< time',request()->post('endTime')];
        }
        if(request()->post('status')!=''){
            $where[]=['status','in',request()->post('status')];
        }
        if(request()->post('min')!=''){
            $where[]=['amount','<=',request()->post('min')];
        }elseif (request()->post('max')!=''){
            $where[]=['amount','>=',request()->post('max')];
        }
        if(request()->post('keywords')!=''){
            $where[]=['order_sn','like','%'.request()->post('keywords').'%'];
        }
        return [$where];
    }
}